from appium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

desired_caps = {
    'platformName':'Android',
    'platformVersion': '7.1.2',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(1)
driver.implicitly_wait(10)

# # 点击-放大镜
# driver.find_element(By.ID, "com.android.settings:id/search").click()
# # 输入-坚果
# driver.find_element(By.ID, "android:id/search_src_text").send_keys("坚果")
# time.sleep(3)
# # clear()
# driver.find_element(By.ID, "android:id/search_src_text").clear()

# # 获取所有id=android:id/title元素
# elements = driver.find_elements(By.ID, "android:id/title")
# for ele in elements:
#     # print(ele.text)
#     print(ele.location)

# # 元素是否可用,返回True或False
# print(driver.find_element(By.XPATH, "//*[@text='设置']").is_enabled())
# print(driver.find_element(By.XPATH, "//*[@text='设置']").is_displayed())

# # 获取app包名和启动名
# print(driver.current_package)
# print(driver.current_activity)

time.sleep(5)
driver.quit()
